<?php

class Application_Model_Departemen extends Zend_Db_Table_Abstract {
    protected $_name = 'tabel_departemen';
    
    public function departemenBaru($departemen, $deskripsi)
    {
        $data = array('nama_departemen' => $departemen, 'deskripsi_departemen' => $deskripsi);
        $this->insert($data);
    }
    
    public function getDepartemen($id) {
        $id = (int)$id;
        $row = $this->fetchRow('id_departemen = '.$id);
        if(!$row)
            throw  new Exception('Data dengan id=$id tidak ditemukan');
        else
            return $row->toArray ();
    }
    
    public function departemenUpdate($id, $departemen, $deskripsi)
    {
        $this->update(array('nama_departemen' => $departemen, 'deskripsi_departemen' => $deskripsi), 'id_departemen = '.(int)$id);   
    }
    
    public function departemenDelete($id){
        $this->delete('id_departemen = '.(int)$id);
    }


    public function checkDepartemen($nama) {
        $select = $this->select();
        $select->where("nama_departemen= ?",$nama);
        $row = $this->fetchAll($select)->count();
        if($row > 0)
            return true;
        else
            return false;
    }
    
    public function checkNamaDepartemen($id) {
        $nama_departemen = $this->select("nama_departemen")->where("id_departemen = ?", $id);
        return $nama_departemen;
    }
}

